package com.alorma.bcn.objects;

import java.util.List;
import java.util.Random;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.alorma.bcn.R;

public class ConsejosAdapter extends ArrayAdapter<ConsejoEntity> {

	private List<ConsejoEntity> datos;
	private Context ctx;
	
    private static Random sRandom = new Random();

    private static final int[] PRESSED_STATE = {
        android.R.attr.state_pressed
    };
	
	public ConsejosAdapter(Context context, int textViewResourceId,
			List<ConsejoEntity> objects) {
		super(context, textViewResourceId, objects);
		datos = objects;
		ctx = context;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		ViewHolder holder = null;
		
		if (convertView == null || !(convertView.getTag() instanceof ViewHolder))
		{
			LayoutInflater mInflater = LayoutInflater.from(ctx);
			convertView = mInflater.inflate(R.layout.rowc, null);
			
			holder = new ViewHolder();
			holder.txtTit = (TextView) convertView.findViewById(R.id.txtRowTitC);
			holder.txtDet = (TextView) convertView.findViewById(R.id.txtRowDetC);
			
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		holder.txtTit.setText(datos.get(position).getTitulo());
		holder.txtDet.setText(datos.get(position).getDetail());
		
		return convertView;
	}
	
	@Override
	public ConsejoEntity getItem(int position) {
		return datos.get(position);
	}
	
	class ViewHolder
	{
		TextView txtTit;
		TextView txtDet;
	}

}